<template>
  <view>
    <scroll-view class="nav-left-container" scroll-y>
      <view class="nav-menu">
        <view
          class="nav-menu-item"
          v-for="(item, index) in list"
          :key="index"
          :class="{ active: active == index }"
          @click="menubar(item, index)"
        >
          <view class="nav-menu-item-text">{{ item.name }}</view>
        </view>
      </view>
    </scroll-view>
  </view>
</template>

<script>
export default {
  name: "siderBar",
  props: {
    list: {
      type: Array,
      default: () => [],
    },
  },
  data() {
    return {
      active: 0,
    };
  },
  methods: {
    menubar(item, index) {
      this.active = index;
      this.$emit("view-to-scroll", index);
    },
  },
};
</script>

<style lang="scss">
.nav-left-container {
  width: 200rpx;
  height: 100%;
  background-color: #fff;
  position: fixed;
  left: 0;
  top: 0;
  z-index: 999;
}
.nav-menu {
  width: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
}
.nav-menu-item {
  width: 100%;
  height: 70rpx;
  display: flex;
  align-items: center;
  justify-content: center;
  border-bottom: 1px solid #e5e5e5;
}
.active {
  border-right: 20rpx solid red;
  background: #e6e6e6;
}
.nav-menu-item-text {
  font-size: 28rpx;
  color: #333;
}
</style>
